<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">制程检验保存</block>
			</cu-custom>
			<!-- 数据列表 -->
			<view class="list">
				<view class="card animation-slide-bottom" v-for="(item,index) in list" :key="index" :style="[{animationDelay: (index + 1)*0.1 + 's'}]">
					<!-- <view class="top">
						<view>行号：<text style="color: red;">{{index +1}}</text></view>
					</view> -->
					<view class="bottom">
						<view class="box">
							<view class="lable">
								检测编码:
							</view>
							<view class="content">
								{{item.projectCode}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								检测名称:
							</view>
							<view class="content">
								{{item.projectName}}
							</view>
						</view>
						<view class="boxs">
							<view class="lable">
								<text class="title" style="background-color: red;">不良品数量：</text>
							</view>
							<view class="content">
								<input style="width: 400rpx;" type="number" v-model="preservationList[index].num" value="" placeholder="请输入不良品数量" />
							</view>
						</view>
						<view class="boxs">
							<view class="lable">
								<text class="title" style="background-color: #99CC00;">检测结果：</text>
							</view>
							<view class="content">
								<!-- <input type="" v-model="preservationList[index].num" value="" placeholder="请输入收货数量" /> -->
								<textarea style="width: 400rpx;" v-model="preservationList[index].txt" value="" placeholder="请输入质检结果" />
								</view>
						</view>
					</view>
				</view>
			</view>
			<view class="btns" v-if="list.length > 0">
				<button class="cu-btn bg-rgb lg" @click="onSubmitPrin">保存</button>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inspectGrade: "",
				materielCode: '',
				list: [],
				preservationList: [],
				objMsg:{}
			}
		},
		onLoad(e) {
			this.objMsg = uni.getStorageSync('processInspectionObj');
			console.log(this.objMsg)
			this.qualityTesting()
		},
		methods: {
			qualityTesting() {
				uni.showLoading({
					mask:true,
					title:'加载中.....'
				})
				let data = {
					inspectGrade: '制程检验',
					materielCode: this.objMsg.mechanismCode
				}
				this.$http.get('inspect/mesMaterielCheckprojrct/getByGrade', {
					params: data
				}).then(res => {
					uni.hideLoading()
					if (res.data.success) {
						this.list = res.data.result
						for (let i = 0; i < this.list.length; i++) {
							let data = {
								num: '',
								txt: '',
								id: this.list[i].id,
								name:this.list[i].projectName,
								code:this.list[i].projectCode
							}
							this.preservationList.push(data)
						}
					} else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			onSubmitPrin(){
				uni.showModal({
					title: '提示',
					content: '本次质检是否合格',
					cancelText: '不合格',
					confirmText: '合格',
					success: res => {
						if (res.confirm) {
							uni.showModal({
								title: '制程检验保存',
								content: '确定要保存本次制程检验合格记录？',
								cancelText: '取消',
								confirmText: '确定',
								success: res => {
									if (res.confirm) {
										uni.showLoading({
											mask:true,
											title:'加载中.....'
										})
										let obj ={
											inspectGrade: this.objMsg.produceGrade,
											materielCode: this.objMsg.mechanismCode,
											materielName: this.objMsg.mechanismName,
											relatedCode: this.objMsg.id,
											inspectQualify:'是',
											mesBadnessInfoList:[]
										}
										for(let i = 0 ; i <this.preservationList.length;i++){
											let data ={
												inspectProject: this.preservationList[i].code + '-' +this.preservationList[i].name,
												inspectResult:this.preservationList[i].txt,
												query2:this.preservationList[i].num
											}
											obj.mesBadnessInfoList.push(data);
										}
										this.$http.post('inspect/mesBadnessHandle/appAdd', obj).then(res => {
											if (res.data.success) {
												// this.$tip.success(res.data.message);
												this.modal.show({ type:'success', content:res.data.message })
												setTimeout(function() {
													uni.navigateBack({
														delta: 1
													})
												}, 1000);
											} else {
												// this.$tip.error(res.data.message)
                        this.modal.show({ type:'error', content:res.data.message })
											}
										})
									}
								}
							})
						}else{
							uni.showModal({
								title: '制程检验保存',
								content: '确定要保存本次制程检验不合格记录？',
								cancelText: '取消',
								confirmText: '确定',
								success: res => {
									if (res.confirm) {
										uni.showLoading({
											mask:true,
											title:'加载中.....'
										})
										let obj ={
											inspectGrade: this.objMsg.produceGrade,
											materielCode: this.objMsg.mechanismCode,
											materielName: this.objMsg.mechanismName,
											relatedCode: this.objMsg.id,
											inspectQualify:'否',
											mesBadnessInfoList:[]
										}
										for(let i = 0 ; i <this.preservationList.length;i++){
											let data ={
												inspectProject: this.preservationList[i].code + '-' +this.preservationList[i].name,
												inspectResult:this.preservationList[i].txt,
												query2:this.preservationList[i].num
											}
											obj.mesBadnessInfoList.push(data);
										}
										this.$http.post('inspect/mesBadnessHandle/appAdd', obj).then(res => {
											if (res.data.success) {
												// this.$tip.success(res.data.message);
												this.modal.show({ type:'success', content:res.data.message })
												setTimeout(function() {
													uni.navigateBack({
														delta: 1
													})
												}, 1000);
											} else {
												// this.$tip.error(res.data.message)
                        this.modal.show({ type:'error', content:res.data.message })
											}
										})
									}
								}
							})
						}
					}
				})
			}
		},
	}
</script>

<style lang="less">
	.card {
		margin: 30rpx;
		box-shadow: 0px 0px 5rpx 2rpx rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		padding: 30rpx;
		background-color: white;
	}

	.card .top {
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #F0F0F0;
		padding-bottom: 20rpx;
		font-weight: bold;
	}

	.card .bottom .box {
		display: flex;
		justify-content: space-between;
		padding: 20rpx 0;
	}

	.card .bottom .box .lable {
		width: 25%;
	}

	.card .bottom .box .content {
		width: 74%;
		text-align: right;
	}
	.boxs{
		display: flex;
		justify-content: space-between;
		padding: 20rpx 0;
		align-items: center;
	}
	.boxs .title{
		font-weight: bold;
		padding: 10rpx;
		border-radius: 10rpx;
		color: white;;
	}
	.boxs input {
		border: 2rpx solid red;
		height: 60rpx;
		padding: 10rpx;
		border-radius: 10rpx;
		font-size: 20rpx;
		color: red;
	}
	.boxs input .input-placeholder{
		color: red;
	}
	uni-textarea{
		border: 2rpx solid #F0F0F0;
		padding: 10rpx;
		border-radius: 10rpx;
		font-size: 20rpx;
	}
	.list{
		margin-bottom: 120rpx;
	}
	.btns{
		position: fixed;
		z-index: 999;
		background: white;
		bottom: 0;
		height: 100rpx;
		line-height: 100rpx;
	}
	.cu-btn{
		width: 650rpx;
		margin-left: 50rpx;
	}
</style>
